<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>系统登录</title>
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="plugins/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="dist/css/font-awesome.min.css">
    <link rel="stylesheet" href="assets/toastr/toastr.min.css"/>

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script>
        if (window.parent != window) { //在框架内
            top.location.href="/" //整个页面跳转
            debugger
        }
    </script>
</head>

<body>

<div class="container">
    <div class="row">
        <div class="col-md-4 col-md-offset-4">
            <div class="login-panel panel panel-info" style="margin-top: 25%;">
                <div class="panel-heading">
                    <h3 class="panel-title">系统登录</h3>
                </div>
                <div class="panel-body">
                    <form role="form" id="loginForm">
                        <fieldset>
                            <div class="form-group">
                                <input class="form-control" placeholder="用户名" name="username" type="text" autofocus>
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="密码" name="password" type="password">
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="验证码" type="text" name="code"
                                       style="width:120px; display:inline-block"/>
                                <a href="javascript:void(0)"><img src="/gifCode" id="validateCodeImg" onclick="reloadCode()"
                                        style="display:inline-block"/></a>
                            </div>
                            <!--<div class="checkbox">
                                <label>
                                    <input name="remember" type="checkbox" value="Remember Me">记住我
                                </label>
                            </div>-->
                            <!-- Change this to a button or input when using this as a form -->
                            <input class="btn btn-lg btn-success btn-block" type="button" onclick="login()" value="登录">
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>


<!-- jQuery 2.2.3 -->
<script src="plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/bootstrap-table/bootstrap-table.js"></script>
<script src="assets/bootstrap-table/bootstrap-table-zh-CN.js"></script>
<script src="assets/toastr/toastr.min.js"></script>
<script src="assets/bootbox/bootbox.js"></script>
<script src="assets/ExTable.js"></script>
<script src="assets/app.js"></script>
<script type="text/javascript">

    function reloadCode() {
        $("#validateCodeImg").attr("src", "/gifCode?data=" + new Date().getTime());
    }

    document.onkeydown = function(e){
        var ev = document.all ? window.event : e;
        if(ev.keyCode==13) {
            login();
        }
    }

    function login() {
        $.ajax({
            url: "/sys/login",
            type: "post",
            data: $("#loginForm").serialize(),
            success: function (item) {
                if (item.code == 200) {
                    window.location = "/";
                } else {
                    //toastr.warning('请重新输入');
                    reloadCode();
                }
            }
        });
    }

</script>

</body>

</html>